package oa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oa.entity.Department;
import oa.entity.User;
import oa.service.UserService;
import oa.service.impl.DepartmentServiceImpl;
import oa.service.impl.UserServiceImpl;

/**
 * Servlet implementation class DeptServlets
 */
@WebServlet("/deptServlets")
public class DeptServlets extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeptServlets() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");//编辑获取值
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		String partid = request.getParameter("id");
		String deptPrincipal = request.getParameter("deptPrincipal");
	    String compantid = request.getParameter("companyid");
	    UserService userService = new UserServiceImpl();
	    DepartmentServiceImpl departim = new DepartmentServiceImpl();
	  
	    //获取本公司的所有员工
	    List<User> userList = userService.selectUser(0, null, 0,Integer.parseInt(compantid));
	     //根据id获取到员工信息
	    List<Department> depart = departim.selectDepartment(Integer.parseInt(partid),null,0);
	    session.setAttribute("UserList", userList);
	    session.setAttribute("listf", depart);
	    session.setAttribute("deptPrincipal", deptPrincipal);
	    session.setAttribute("compantid", compantid);
		request.getRequestDispatcher("dept_up.jsp").forward(request, response);
	}  

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
